import java.util.HashMap;
import java.util.Map;

/**
 * @Author Stringzhua
 * @Date 2024/9/26 18:59
 * description:
 * step1:为了覆盖所有的结果路径,需要依次检查所有的元素
 * step2:针对对应的已选定的元素,尝试在输入中寻找与所选数字求和等于目标值的数字
 * <p>
 * 暴力解
 * <p>
 * 哈希解
 */
public class lc1p2 {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int choose = nums[i];
            int diff = target - choose;
            if (map.containsKey(diff)) {
                return new int[] {map.get(diff),i};
            }
            map.put(choose,i);
        }
        return null;
    }
}
